import { ElMessageBox, ElNotification } from "element-plus"

export const dialog = {

    succ(msg: string, duration = 800) {
        ElNotification({
            title: '成功',
            message: msg,
            type: 'success',
            duration: duration,
            position: 'bottom-right',
        });
    },

    info(msg: string) {
        ElNotification({
            title: '通知',
            message: msg,
            type: 'info',
            duration: 800,
            position: 'bottom-right',
        });
    },

    err(msg: any) {
        ElMessageBox({
            title: '错误',
            message: msg as string,
            showCancelButton: false,
            showConfirmButton: false,
            confirmButtonText: '确定',
            type: 'error',
            autofocus: false,
            closeOnClickModal: false,
            draggable: true,
        })
        .then((v) => {})
        .catch((v) => {});
    }
}

const HEX_LIST = [
    '0', '1', '2', '3',
    '4', '5', '6', '7',
    '8', '9', 'A', 'B',
    'C', 'D', 'E', 'F',
];

export function hex4(value: number) {
    const h0 = (value >> 12) & 0x0F;
    const h1 = (value >> 8) & 0x0F;
    const h2 = (value >> 4) & 0x0F;
    const h3 = value & 0x0F;
    return `${HEX_LIST[h0]}${HEX_LIST[h1]}${HEX_LIST[h2]}${HEX_LIST[h3]}`;
}
